<template>
    <div class="modification">
        <div id="eTermTip" v-if="eTermTip.tip">{{eTermTip.text}}</div>
        <div style="display:none">{{para.id}}</div>
        <div class="modification-clear" @click="readd"></div>
        <div class="modification-class modification-values">
            <div class="modification-Key">账号类型：</div>
            <div class="modification-value">
                <span class="modification-rotate"></span>
                <ul class="modification-list">
                    <li>中航信eTerm</li>
                </ul>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">用户名：</div>
            <div class="modification-value">
                <input class="modification-input p-user" name="eTermName" type="text" placeholder="第三方系统配置号" v-model='para.eTermName'>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">密码：</div>
            <div class="modification-value">
                <input class="modification-input p-pas" name="password" type="password" placeholder="第三方系统配置号密码" v-model='para.password'> <span class="modification-pas" v-if="1==0"></span>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">工作号：</div>
            <div class="modification-value">
                <input class="modification-input p-jobn" name="wordName" type="text" placeholder="第三方系统二级账号" v-model='para.wordName'>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">工作号密码：</div>
            <div class="modification-value">
                <input class="modification-input p-jobp" name="wordPassword" type="password" placeholder="第三方系统二级账号密码" v-model='para.wordPassword'> <span class="modification-pas" v-if="1==0"></span>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">级别：</div>
            <div class="modification-value">
                <input class="modification-input p-level" name="lvl" type="number" maxlength="2" v-model='para.lvl'>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">eTermIP：</div>
            <div class="modification-value">
                <input class="modification-input p-etermIp" name="ip" type="text" placeholder="eTermIP服务器地址" v-model='para.ip'>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">eTerm端口：</div>
            <div class="modification-value modification-port">
                <input class="modification-input p-etermPort" name="port" type="number" placeholder="端口号" v-model='para.port'>
            </div>
            <div class="secure-transport">
                <input class="p-Secure" type="checkbox" name="security" :checked="para.security" @click='para.security=!para.security'><span>安全传输</span>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">si指令：</div>
            <div class="modification-value modification_siInput">
                <span v-text="si_q"></span>
                <input class="modification-input p-si" style="width: 0px" name="si" type="text" v-model='para.si'>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">自动采集时间：</div>
            <div class="acquisition-time">
                <input type="text" name="auto" v-model='listOne.time.data1' @input="changeTime" maxlength="1"> <input type="text" name="auto1" v-model='listOne.time.data2' @input="changeTime" maxlength="1"> <span>：</span> <input type="text" maxlength="1" name="auto2" v-model='listOne.time.data3' @input="changeTime"> <input type="text" maxlength="1" name="auto3" v-model='listOne.time.data4' @input="changeTime"> <span class="modK" @mouseout="tipC" @mouseover="tip(tipContent.tip2,$event)"></span>
            </div>
        </div>
        <div class="modification-class conflict-class-resolution">
            <div class="modification-Key">账号冲突处理：</div>
            <div class="conflict-resolution">
                <input class="p-conflict" type="number" name="avoidTime" v-model='para.avoidTime'> <span>分钟</span> <input class="p-conflictAvoid" type="radio" :checked="true"> <span>冲突时自动避让</span> <span class="conR" @mouseout="tipC" @mouseover="tip(tipContent.tip1,$event)"></span>
            </div>
        </div>
        <div class="modification-class">
            <div class="modification-Key">深度采集：</div>
            <div class="epth-acquisition">
                <input type="radio" name="che" id="radio-state" value="1" :checked="para.che" @click='cheChange(true)'><span>是</span> <input type="radio" name="che" id="radio-jia" value="0" :checked="!para.che" @click='cheChange(false)'><span>否</span>
                <span class="epA" @mouseout="tipC" @mouseover="tip(tipContent.tip3,$event)"></span>
            </div>
        </div>
        <div class="modification-class collection-scope" v-if="para.che">
            <div class="modification-Key">采集范围：</div>
            <div class="collection-scope-box">
                <div>航班号</div>
                <div>航线</div>
                <span class="cosb" @mouseout="tipC" @mouseover="tip(tipContent.tip4,$event)"></span>
            </div>
        </div>
        <div class="modification-specia specia0"  v-if="para.che">
            <div class="speciaList-tag"></div>
            <div class="modification-speciaList">
                <div>
                    <div>
                        <input type="text" class="speciaList-in1" name="flb_nbr1" placeholder="AA0000" v-model='para.flb_nbr1'>
                    </div>
                    <div>
                        <input type="text" class="speciaList-in2" name="flt_rte_cd1" placeholder="AAABBBCCC" v-model='para.flt_rte_cd1'>
                    </div>
                </div>
                <div>
                    <div>
                        <input type="text" class="speciaList-in1" name="flb_nbr2" placeholder="AA0000" v-model='para.flb_nbr2'>
                    </div>
                    <div>
                        <input type="text" class="speciaList-in2" name="flt_rte_cd2" placeholder="AAABBBCCC" v-model='para.flt_rte_cd2'>
                    </div>
                </div>
            </div>
        </div>
        <div class="modification-specia specia0"  v-if="para.che">
            <div class="speciaList-tag"></div>
            <div class="modification-speciaList">
                <div>
                    <div>
                        <input type="text" class="speciaList-in1" name="flb_nbr3" placeholder="AA0000" v-model="para.flb_nbr3">
                    </div>
                    <div>
                        <input type="text" class="speciaList-in2" name="flt_rte_cd3" placeholder="AAABBBCCC" v-model="para.flt_rte_cd3">
                    </div>
                </div>
                <div>
                    <div>
                        <input type="text" class="speciaList-in1" name="flb_nbr4" placeholder="AA0000" v-model="para.flb_nbr4">
                    </div>
                    <div>
                        <input type="text" class="speciaList-in2" name="flt_rte_cd4" placeholder="AAABBBCCC" v-model="para.flt_rte_cd4">
                    </div>
                </div>
            </div>
        </div>
        <div class="modification-specia specia0"  v-if="para.che">
            <div class="speciaList-tag"></div>
            <div class="modification-speciaList">
                <div>
                    <div>
                        <input type="text" class="speciaList-in1" name="flb_nbr5" placeholder="AA0000" v-model="para.flb_nbr5">
                    </div>
                    <div>
                        <input type="text" class="speciaList-in2" name="flt_rte_cd5" placeholder="AAABBBCCC" v-model="para.flt_rte_cd5">
                    </div>
                </div>
                <div>
                    <div>
                        <input type="text" class="speciaList-in1" name="flb_nbr6" placeholder="AA0000" v-model="para.flb_nbr6">
                    </div>
                    <div>
                        <input type="text" class="speciaList-in2" name="flt_rte_cd6" placeholder="AAABBBCCC" v-model="para.flt_rte_cd6">
                    </div>
                </div>
            </div>
        </div>
        <div class="modification-sub" @click="addEterm"  v-if="para.che">提交</div>
    </div>
</template>
<script>
    var re = /^(?:[01]\d|2[0-3])(?::[0-5]\d)$/;
    export default{
        data(){
            return{
                isOk:false,
                eTermTip:{
                    tip:false,
                    text:''
                },
                para:{
                    id:'',
                    eTermName:'',
                    password:'',
                    wordName:'',
                    wordPassword:'',
                    lvl:'',
                    ip:'',
                    port:'',
                    che:true,
                    security:true,
                    si:'',
                    auto:'',
                    avoidTime:'',
                    flb_nbr1:'',
                    flt_rte_cd1:'',
                    flb_nbr2:'',
                    flt_rte_cd2:'',
                    flb_nbr3:'',
                    flt_rte_cd3:'',
                    flb_nbr4:'',
                    flt_rte_cd4:'',
                    flb_nbr5:'',
                    flt_rte_cd5:'',
                    flb_nbr6:'',
                    flt_rte_cd6:''
                },
                listOne:{
                    time:{
                        data1:'',
                        data2:'',
                        data3:'',
                        data4:''
                    }
                },
                tipContent:{
                    tip2:'指定当系统自动采集任务进行中发现账号被人为登录造成账号使用冲突，系统自动暂停采集的时间间隔。',
                    tip1:'指定系统自动执行数据采集任务的开始时间。因中航信数据归档会重置连接，请尽量避免凌晨三点左右执行采集任务。',
                    tip3:'深度采集会采集乘客票面级别数据，收入分析更精确，并且可提供客源组成分析。',
                    tip4:'在选择深度采集时，因指令量较大需指定待采航班号，为避免账号行为异常，建议每个账号指定不超过3个航班对。',
                }
            }
        },
        computed:{
            pas:function () {
                let che=()=>{
                    if(this.para.che==true){
                        return '1'
                    }else {
                        return '0'
                    }
                };
                let security=()=>{
                    if(this.para.security==true){
                        return 'yes'
                    }else if(this.para.security==false){
                        return 'no'
                    }
                };
                let listD={
                    id:this.para.id,
                    eTermName:this.para.eTermName,
                    password:this.para.password,
                    wordName:this.para.wordName,
                    wordPassword:this.para.wordPassword,
                    lvl:this.para.lvl,
                    ip:this.para.ip,
                    port:this.para.port,
                    security:security(),
                    si:this.si_q + this.para.si,
                    auto:this.para.auto,
                    avoidTime:this.para.avoidTime,
                    che:che(),
                };
                if(this.para.flb_nbr1!=''){
                    listD.flb_nbr1=this.para.flb_nbr1;
                    listD.flt_rte_cd1=this.para.flt_rte_cd1;
                    listD.flb_nbr2=this.para.flb_nbr2;
                    listD.flt_rte_cd2=this.para.flt_rte_cd2;
                }
                if(this.para.flb_nbr3!=''){
                    listD.flb_nbr3=this.para.flb_nbr3;
                    listD.flt_rte_cd3=this.para.flt_rte_cd3;
                    listD.flb_nbr4=this.para.flb_nbr4;
                    listD.flt_rte_cd4=this.para.flt_rte_cd4;
                }
                if(this.para.flb_nbr5!=''){
                    listD.flb_nbr5=this.para.flb_nbr5;
                    listD.flt_rte_cd5=this.para.flt_rte_cd5;
                    listD.flb_nbr6=this.para.flb_nbr6;
                    listD.flt_rte_cd6=this.para.flt_rte_cd6;
                }
                return listD
            },
            si_q:function () {
                return "si/" + this.para.wordName + "/" + this.para.wordPassword;
            }
        },
        props:['cData'],
        mounted:function () {
            if(this.cData!=''){
                let che=()=>{
                    if(this.cData.info.depth==1){
                        return true
                    }else {
                        return false
                    }
                };
                let security=()=>{
                    if(this.cData.info.secure==1){
                        return true
                    }else {
                        return false
                    }
                };
                let time=()=>{
                   let ds=this.cData.info.broken[0].toString()+this.cData.info.broken[1].toString()+':'+this.cData.info.broken[2].toString()+this.cData.info.broken[3].toString();
                    return ds;
                };
                this.listOne.time.data1=this.cData.info.broken[0];
                this.listOne.time.data2=this.cData.info.broken[1];
                this.listOne.time.data3=this.cData.info.broken[2];
                this.listOne.time.data4=this.cData.info.broken[3];
                let cs_Arr = this.cData.info.si.split("/");
                let cs_si = "";
                for(let i = 0; i < cs_Arr.length; i++){
                    if(i > 2){
                        cs_si += ("/" + cs_Arr[i]);
                    }
                };
                this.para={
                    id:this.cData.info.id,
                    eTermName:this.cData.info.user,
                    password:this.cData.info.pas,
                    wordName:this.cData.info.jobn,
                    wordPassword:this.cData.info.jobp,
                    lvl:this.cData.info.level,
                    ip:this.cData.info.etermIp,
                    port:this.cData.info.etermPort,
                    che:che(),
                    security:security(),
                    si:cs_si,
                    auto:time(),
                    avoidTime:this.cData.info.conflict,
                    flb_nbr1:this.cData.info.addFltNbrs[0] != undefined ? this.cData.info.addFltNbrs[0].flt_Nbr :"",
                    flt_rte_cd1:this.cData.info.addFltNbrs[0] != undefined ? this.cData.info.addFltNbrs[0].air_line :"",
                    flb_nbr2:this.cData.info.addFltNbrs[1] != undefined ? this.cData.info.addFltNbrs[1].flt_Nbr :"",
                    flt_rte_cd2:this.cData.info.addFltNbrs[1] != undefined ? this.cData.info.addFltNbrs[1].air_line :"",
                    flb_nbr3:this.cData.info.addFltNbrs[2] != undefined ? this.cData.info.addFltNbrs[2].flt_Nbr :"",
                    flt_rte_cd3:this.cData.info.addFltNbrs[2] != undefined ? this.cData.info.addFltNbrs[2].air_line :"",
                    flb_nbr4:this.cData.info.addFltNbrs[3] != undefined ? this.cData.info.addFltNbrs[3].flt_Nbr :"",
                    flt_rte_cd4:this.cData.info.addFltNbrs[3] != undefined ? this.cData.info.addFltNbrs[3].air_line :"",
                    flb_nbr5:this.cData.info.addFltNbrs[4] != undefined ? this.cData.info.addFltNbrs[4].flt_Nbr :"",
                    flt_rte_cd5:this.cData.info.addFltNbrs[4] != undefined ? this.cData.info.addFltNbrs[4].air_line :"",
                    flb_nbr6:this.cData.info.addFltNbrs[5] != undefined ? this.cData.info.addFltNbrs[5].flt_Nbr :"",
                    flt_rte_cd6:this.cData.info.addFltNbrs[5] != undefined ? this.cData.info.addFltNbrs[5].air_line :""
                };

            };
        },
        methods:{
            cheChange:function (val) {
                this.para.che=val;
            },
            input:function (type) {

            },
            changeTime:function () {
                this.para.auto=this.listOne.time.data1+this.listOne.time.data2+':'+this.listOne.time.data3+this.listOne.time.data4;
            },
            addEterm:function () {
                this.isOk=true;
                if(this.para.eTermName==''){
                    this.isOk=false;
                    this.eTermTip.text='eTerm账号名不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(this.para.password==''){
                    this.isOk=false;
                    this.eTermTip.text='eTerm密码不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }
//                else if(this.para.wordName==''){
//                    this.isOk=false;
//                    this.eTermTip.text='工作号不能为空';
//                    this.eTermTip.tip=true;
//                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
//                }else if(this.para.wordPassword==''){
//                    this.eTermTip.text='工作号密码不能为空';
//                    this.eTermTip.tip=true;
//                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
//                }
                else if(this.para.lvl==''){
                    this.isOk=false;
                    this.eTermTip.text='级别不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(this.para.ip==''){
                    this.isOk=false;
                    this.eTermTip.text='eTerm端口不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(this.para.si==''){
                    this.isOk=false;
                    this.eTermTip.text='si指令不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(this.para.auto==''){
                    this.isOk=false;
                    this.eTermTip.text='采集时间不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(!re.test(this.para.auto)){
                    this.isOk=false;
                    this.eTermTip.text='采集时间格式错误！ 正确格式 例如：23:56';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(this.para.avoidTime==''){
                    this.isOk=false;
                    this.eTermTip.text='账号冲突时间不能为空';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(parseInt(this.para.avoidTime)<0){
                    this.isOk=false;
                    this.eTermTip.text='账号冲突时间不能为负数';
                    this.eTermTip.tip=true;
                    setTimeout(()=>{ this.eTermTip.tip=false},1500)
                }else if(this.para.che==true){
                    if(this.para.flb_nbr1!=''||this.para.flb_nbr1!=''||this.para.flb_nbr2!=''||this.para.flb_nbr2!=''){
                        if(this.para.flb_nbr1!=''&&this.para.flb_nbr1!=''&&this.para.flb_nbr2!=''&&this.para.flb_nbr2!=''){

                        }else{
                            this.isOk=false;
                            this.eTermTip.text='请完善航班信息，例如 GJ8430 HGHWDSXIY';
                            this.eTermTip.tip=true;
                            setTimeout(()=>{ this.eTermTip.tip=false},1500)
                        }
                    }
                    if(this.para.flb_nbr3!=''||this.para.flb_nbr3!=''||this.para.flb_nbr4!=''||this.para.flb_nbr4!=''){
                        if(this.para.flb_nbr3!=''&&this.para.flb_nbr3!=''&&this.para.flb_nbr4!=''&&this.para.flb_nbr4!=''){

                        }else {
                            this.isOk=false;
                            this.eTermTip.text='请完善航班信息，例如 GJ8430 HGHWDSXIY';
                            this.eTermTip.tip=true;
                            setTimeout(()=>{ this.eTermTip.tip=false},1500)
                        }
                    }
                    if(this.para.flb_nbr5!=''||this.para.flb_nbr5!=''||this.para.flb_nbr6!=''||this.para.flb_nbr6!=''){
                        if(this.para.flb_nbr5!=''&&this.para.flb_nbr5!=''&&this.para.flb_nbr6!=''&&this.para.flb_nbr6!=''){

                        }else {
                            this.isOk=false;
                            this.eTermTip.text='请完善航班信息，例如 GJ8430 HGHWDSXIY';
                            this.eTermTip.tip=true;
                            setTimeout(()=>{ this.eTermTip.tip=false;},1500)
                        }
                    }
                }
                if(this.isOk==true){
                    if(this.cData!=''){
                        $.ajax({
                            url:'/addeTerm',
                            type:"post",
                            data:this.pas,
                            success:(data)=>{
                                if(data.success){
                                    this.eTermTip.text=data.message;
                                    this.eTermTip.tip=true;
                                    setTimeout(()=>{
                                        this.eTermTip.tip=false;
                                        this.readd();
                                    },1500);
                                }
                            }
                        });
                    }else {
                        $.ajax({
                            url:'/addeTerm',
                            type:"post",
                            data:this.pas,
                            success:(data)=>{
                                if(data.success){
                                    this.eTermTip.text=data.message;
                                    this.eTermTip.tip=true;
                                    setTimeout(()=>{
                                        this.eTermTip.tip=false;
                                        this.readd();
                                    },1500);
                                }
                            }
                        });
                    }
                }
            },
            tip:function (val,e) {
                let data={
                    val:val,
                    e:e,
                    isTrue:true
                };
                this.$emit('tip',data);
            },
            tipC:function () {
                let data={
                    isTrue:false
                };
                this.$emit('tip',data);
            },
            readd:function () {
                let das={
                    isTrue:false,
                    remove:true
                };
                this.$emit('tip',das);
            }
        }
    }
</script>
<style scoped>
    input[type=radio] {
        position: static;
        top: -9999px;
    }
    .modification_siInput{
        display: flex;
    }
    .modification_siInput>input{
        flex: 1;
        padding: 0;
    }
    .modification_siInput>span{
        width: auto;
        color: white;
    }
    #eTermTip{
        width: 250px;
        height: 30px;
        border:1px solid #73abff;
        position: absolute;
        top: 0px;
        border-radius: 3px;
        bottom: 0px;
        margin: auto;
        left: 0px;
        right: 0px;
        z-index: 99;
        background-color: #f2dede;
        font-size: 12px;
        padding: 3px;
        text-align: center;
        color: #d9534f ;
    }
</style>
